home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / netBoot.new / h / keyboard.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-19  |  11.0 KB  |  292 lines

  1.  
  2. /*    @(#)keyboard.h 1.1 86/09/27 SMI    */
  3.  
  4. /*
  5.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  6.  */
  7.  
  8. /*
  9.  * Header file for Sun Microsystems keyboard routines
  10.  *
  11.  * The keyboard is a standard Micro Switch, or otherwise, keyboard,
  12.  * with an 8048/8748 on the board.  This has been modified to produce
  13.  * up/down keycodes.
  14.  *
  15.  * On Sun-1 keyboards these keycodes are output on 8 parallel output lines.
  16.  * Each keycode is held stable on these lines for a minimum of 2.5 ms in
  17.  * order that the main processor can read it during its refresh
  18.  * routine, which executes every 2 ms or so.  
  19.  *
  20.  * On Sun-2 keyboards, the keycodes are transmitted on a serial line
  21.  * at 1200 baud.
  22.  *
  23.  * When no physical keys are depressed, the keyboard transmits a keycode of
  24.  * "IDLE" (7F hex), to indicate that.  Thus, when the last key is released,
  25.  * a keycode for its release is sent, then an IDLE.  Note that virtual
  26.  * keys on the VT100 kbd (eg CAPS LOCK) can be down when the IDLE code
  27.  * is received.
  28.  *
  29.  * The Sun-1 VT100 keyboard will follow each of its IDLE's with a
  30.  * keyboard id code, identifying the key layout or other factors
  31.  * which host programs might want to automatically determine.
  32.  * The support for this feature is marked with "#ifdef KBDID".
  33.  * The only good it currently does us is to tell us the state of
  34.  * the "caps lock" LED/virtual key when we have been reset.
  35.  *
  36.  * The low 4 bits of the id byte contain the keyboard ID (currently
  37.  * 1 for VT100 keyboard); the high order bit is set (to make sure
  38.  * there's a transition between the IDLE (7F) and the identification
  39.  * byte); the -XXX---- bits contain state information about the keyboard.
  40.  * These bits are allocated from opposite ends in case we need to shift
  41.  * the boundary.  The only state bit currently defined is 0x40, which is
  42.  * the current state of the CAPS LOCK LED.
  43.  *
  44.  * The Sun-2 keyboard also transmits two other "special" keycodes:
  45.  *
  46.  *    RESETKEY    upon power-up, when no errors are detected,
  47.  *            this code is sent and followed by the keyboard id,
  48.  *            a byte containing 0x02.
  49.  *
  50.  *    ERRORKEY    upon power-up, when errors are detected, 
  51.  *            this code is sent and followed by a "cause" byte
  52.  *            giving more details.  There is only one cause byte
  53.  *            defined so far -- checksum error on PROM.
  54.  *
  55.  * Due to table size limits, the configuration file for the
  56.  * ROM monitor must specify what keyboard it will support, by using:
  57.  *     options KEYBKL or KEYBVT or KEYBS2
  58.  *
  59.  */
  60.  
  61. #ifndef IDLEKEY
  62.  
  63. /*
  64.  * Various special characters that might show up on the port
  65.  */
  66.  
  67. /* Both of these are followed by 1 byte of parameters. */
  68. #define    RESETKEY    0xFF        /* Keyboard was just reset */
  69. #define    ERRORKEY    0x7E        /* Keyboard detected an error */
  70. #define    IDLEKEY        0x7F        /* Keyboard is idle; no keys down */
  71. #define    PRESSED        0x00        /* 0x80 bit off: key was pressed */
  72. #define    RELEASED    0x80        /* 0x80 bit on : key was released */
  73.  
  74. /*
  75.  * Keyboard-specific information
  76.  */
  77. /* Sun-2 keyboard wired-in information */
  78. #define    KB_UNKNOWN    0x06        /* Random unlikely to be seen */
  79. #define    ABORTKEY1    1        /* First key of abort seq - L1 */
  80. #define    ABORTKEY2    77        /* 2nd key of abort seq - "A" */
  81.  
  82. /*
  83.  * Keyboard ID codes...transmitted by the various keyboards
  84.  * after the IDLEKEY code.  See top of file for more details.
  85.  * N.B.: Only the low order 4 bits encode the keyboard id;
  86.  *  don't forget to mask off the high nibble.
  87.  * The value of KB_UNKNOWN above must not match any of these,
  88.  * if KBDID is set.
  89.  */
  90. #define    KB_MS_103SD32    0x00        /* Micro Switch 103SD32-2 */
  91. #define    KB_VT100    0x01        /* Keytronics VT100 compatible */
  92. #define    KB_SUN2        0x02        /* Sun-2 custom keyboard */
  93.  
  94. /*
  95.  * Commands to the Sun-2 keyboard.
  96.  */
  97. #define    KBD_CMD_RESET    0x01        /* Reset keyboard as if power-up */
  98. #define    KBD_CMD_BELL    0x02        /* Turn on the bell */
  99. #define    KBD_CMD_NOBELL    0x03        /* Turn off the bell */
  100. #define    KBD_CMD_LED1    0x04        /* Turn on LED 1 */
  101. #define    KBD_CMD_NOLED1    0x05        /* Turn off LED 1 */
  102. #define    KBD_CMD_LED2    0x06        /* Turn on LED 2 */
  103. #define    KBD_CMD_NOLED2    0x07        /* Turn off LED 2 */
  104.  
  105. /*
  106.  * Commands to the Sun-3 keyboard.
  107.  */
  108. #define KBD_CMD_CLICK   0x0A            /* Turn on keyboard click */
  109. #define KBD_CMD_NOCLICK 0x0B        /* Turn off keyboard click */
  110.  
  111. /*
  112.  * Software related definitions
  113.  */
  114. /*
  115.  * These are the states that the keyboard scanner can be in.
  116.  *
  117.  * It starts out in STARTUP state.
  118.  */
  119. #define    STARTUP        0        /* Waiting for kbd to show up */
  120. #define    NORMAL        1        /* The usual (ho, hum) */
  121. #define    ABORT1        2        /* Got KEYABORT1 */
  122. #define    IDLE1        3        /* Got IDLE */
  123. #define    IDLE2        4        /* Got id byte, IDLE probably follows */
  124. #define    STARTUP2    5        /* Got 1st byte of startup */
  125. #define    STARTUPERR    6        /* Got 1st byte of error startup */
  126.  
  127.  
  128. /*
  129.  * Translation options for getkey()
  130.  *
  131.  * These are how you can have your input translated.
  132.  */
  133. #define    TR_NONE        0
  134. #define    TR_ASCII    1
  135.  
  136. /*
  137.  * These bits can appear in the result of TR_NONE getkey()s.
  138.  */
  139. #define    STATEOF(key)    ((key) & 0x80)    /* 0 = key down, 0x80 = key up */
  140. #define    KEYOF(key)    ((key) & 0x7F)    /* The key number that moved */
  141. #define    NOKEY        (-1)        /* The argument was 0, and no key was
  142.                        depressed.  They were all elated. */
  143.  
  144. /*
  145.  * These bits can appear in the result of TR_ASCII getkey()s.
  146.  * (NOKEY can also appear if no keypress was queued up.)
  147.  */
  148. #define    METABIT        0        /* Meta key depressed with key */
  149. #define    METAMASK    0x000080
  150. #define    SYSTEMBIT    1        /* Upper left key was down w/key */
  151. #define    SYSTEMMASK    0x000100
  152. /* other "bucky" bits can be defined at will.  See "BUCKYBITS" below. */
  153.  
  154. /*
  155.  * This defines the bit positions used within "shiftmask" to
  156.  * indicate the "pressed" (1) or "released" (0) state of shift keys.
  157.  * Both the bit numbers, and the aggregate masks, are defined.
  158.  *
  159.  * The "UPMASK" is a minor kludge.  Since whether the key is going
  160.  * up or down determines the translation table (just as the shift
  161.  * keys' positions do), we OR it with "shiftmask" to get "tempmask",
  162.  * which is the mask which is actually used to determine the 
  163.  * translation table to use.  Don't reassign 0x0080 for anything
  164.  * else, or we'll have to shift and such to squeeze in UPMASK,
  165.  * since it comes in from the hardware as 0x80.
  166.  */
  167. #define    CAPSLOCK    0        /* Caps Lock key */
  168. #define    CAPSMASK    0x0001
  169. #define    SHIFTLOCK    1        /* Shift Lock key */
  170. #define    LEFTSHIFT    2        /* Left-hand shift key */
  171. #define    RIGHTSHIFT    3        /* Right-hand shift key */
  172. #define    SHIFTMASK    0x000E
  173. #define    LEFTCTRL    4        /* Left-hand (or only) control key */
  174. #define    RIGHTCTRL    5        /* Right-hand control key */
  175. #define ALT        6        /* Alternate key */
  176. #define    CTRLMASK    0x0030
  177. /* unused...        0x0040 */
  178. #define    UPMASK    0x0080
  179. #define    CTLSMASK    0x0100      /* Set if ^S was last keyed of ^S, ^Q;
  180.                        determines which NOSCOLL sends. */
  181.  
  182. /*
  183.  * This defines the format of translation tables.
  184.  *
  185.  * A translation table is 128 bytes of "entries", which are bytes
  186.  * (unsigned chars).  The top 4 bits of each entry are decoded by
  187.  * a case statement in getkey.c.  If the entry is less than 0x80, it
  188.  * is sent out as an ASCII character (possibly with bucky bits
  189.  * OR-ed in).  "Special" entries are 0x80 or greater, and
  190.  * invoke more complicated actions.
  191.  */
  192. struct keymap {
  193.     unsigned char    keymap[128];    /* maps keycodes to actions */
  194. };
  195.  
  196. /*
  197.  * A keyboard is defined by its keymaps and what state it resets at idle.
  198.  *
  199.  * The masks k_idleshifts and k_idlebuckys are AND-ed with the current
  200.  * state of  shiftmask  and  buckybits  when a "keyboard idle" code
  201.  * is received.  This ensures that where we "think" the shift & bucky
  202.  * keys are, more accurately reflects where they really are, since the
  203.  * keyboard knows better than us.
  204.  */
  205. struct keyboard {
  206.     struct keymap    *k_normal;    /* Unshifted */
  207.     struct keymap    *k_shifted;    /* Shifted */
  208.     struct keymap    *k_caps;    /* Caps locked */
  209.     struct keymap    *k_control;    /* Controlled */
  210.     struct keymap    *k_up;        /* Key went up */
  211.     int        k_idleshifts;    /* Shifts that keep across idle */
  212.     int        k_idlebuckys;    /* Bucky bits that keep across idle */
  213. };
  214.  
  215.  
  216. /*
  217.  * The "special" entries' top 4 bits are defined below.  Generally they are
  218.  * used with a 4-bit parameter (such as a bit number) in the low 4 bits.
  219.  * The bytes whose top 4 bits are 0x0 thru 0x7 happen to be ascii 
  220.  * characters.  They are not special cased, but just normal cased.
  221.  */
  222.  
  223. #define    SHIFTKEYS    0x80    /* thru 0x8F.  This key helps to determine the
  224.                    translation table used.  The bit
  225.                    position of its bit in "shiftmask"
  226.                    is added to the entry, eg
  227.                    SHIFTKEYS+LEFTCTRL.  When this entry is
  228.                    invoked, the bit in "shiftmask" is
  229.                    toggled.  Depending which tables you put
  230.                    it in, this works well for hold-down
  231.                    keys or press-on, press-off keys.  */
  232. #define    BUCKYBITS    0x90    /* thru 0x9F.  This key determines the state of
  233.                    one of the "bucky" bits above the
  234.                    returned ASCII character.  This is
  235.                    basically a way to pass mode-key-up/down
  236.                    information back to the caller with each
  237.                    "real" key depressed.  The concept, and
  238.                    name "bucky" (derivation unknown) comes
  239.                    from the MIT/SAIL "TV" system...they had
  240.                    TOP, META, CTRL, and a few other bucky
  241.                    bits.  The bit position of its bit in
  242.                    "buckybits", minus 7, is added to the
  243.                    entry; eg bit 0x00000400 is BUCKYBITS+3.
  244.                    The "-7" prevents us from messing up the
  245.                    ASCII char, and gives us 16 useful bucky
  246.                    bits.  When this entry is invoked,
  247.                    the designated bit in "buckybits" is
  248.                    toggled.  Depending which tables you put
  249.                    it in, this works well for hold-down
  250.                    keys or press-on, press-off keys.  */
  251. #define    FUNNY        0xA0    /* thru 0xAF.  This key does one of 16 funny
  252.                    things based on the low 4 bits: */
  253. #define    NOP        0xA0    /* This key does nothing. */
  254. #define    OOPS        0xA1    /* This key exists but is undefined. */
  255. #define    HOLE        0xA2    /* This key does not exist on the keyboard.
  256.                    Its position code should never be
  257.                    generated.  This indicates a software/
  258.                    hardware mismatch, or bugs. */
  259. #define    NOSCROLL    0xA3    /* This key alternately sends ^S or ^Q */
  260. #define    CTRLS        0xA4    /* This sends ^S and lets NOSCROLL know */
  261. #define    CTRLQ        0xA5    /* This sends ^Q and lets NOSCROLL know */
  262. #define    RESET        0xA6    /* Kbd was just reset */
  263. #define    ERROR        0xA7    /* Kbd just detected an internal error */
  264. #define    IDLE        0xA8    /* Kbd is idle (no keys down) */
  265. /* Combinations 0xA9 to 0xAF are reserved for non-parameterized functions */
  266.  
  267. #define    STRING        0xB0    /* thru 0xBF.  The low-order 4 bits index
  268.                    a table referenced via gp->KStrTab and
  269.                    select a string to be returned, char
  270.                    by char.  Each entry in KStrTab is a
  271.                    pointer to a character vector.  The vector
  272.                    contains a 1-byte length, followed by
  273.                    data. */
  274. /* Definitions for the individual string numbers: */
  275. #define    HOMEARROW    0x00
  276. #define    UPARROW        0x01
  277. #define    DOWNARROW    0x02
  278. #define    LEFTARROW    0x03
  279. #define    RIGHTARROW    0x04
  280. #define    PF1        0x05
  281. #define    PF2        0x06
  282. #define    PF3        0x07
  283. #define    PF4        0x08
  284. /* Note, these might be better served by their own non-FUNNY code with the
  285.    low 4 bits selecting which PF key.... */
  286. /* string numbers 9 thru F are reserved.  Users making custom entries, take
  287.    them from F downward to postpone confusion. */
  288.  
  289. /* combinations 0xC0 - 0xFF are reserved for more argument-taking entries */
  290.  
  291. #endif IDLEKEY
  292.